package com.mairuide.phone.callanalysis.controller;

import java.io.*;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import com.mairuide.bill.utils.DateUtils;
import com.mairuide.bill.utils.ExcelUtils;
import com.mairuide.phone.trackevents.TrackEventsParams;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mairuide._frame.base.BaseController;
import com.mairuide._frame.base.ModuleCode;
import com.mairuide.bill.utils.ExcelUtil;
import com.mairuide.datalog.ActionType;
import com.mairuide.datalog.DataOperationLogService;
import com.mairuide.datalog.ModuleFlag;
import com.mairuide.datalog.SystemFlag;
import com.mairuide.entity.PageResult;
import com.mairuide.entity.Result;
import com.mairuide.entity.StatusCode;
import com.mairuide.phone.PhoneRecord;
import com.mairuide.phone.callanalysis.CallanalysisVo;
import com.mairuide.phone.callanalysis.entity.PhoneSearchDto;
import com.mairuide.phone.callanalysis.service.CallAnalysisD3Service;
import com.mairuide.phone.callanalysis.service.CallAnalysisService;
import com.mairuide.phone.trackevents.TrackEventsService;

/**
 * Created by 敲代码的卡卡罗特
 * on 2018/12/17 14:26.
 */
@Controller
@RequestMapping("callanalysis")
public class CallAnalysisController extends BaseController {
	@Autowired
    private DataOperationLogService dataOperationLogService;
    @Autowired
    private CallAnalysisService callAnalysisService;
    @Autowired
    private TrackEventsService trackEventsService;
    @Autowired
    private CallAnalysisD3Service callAnalysisD3Service;
    @ModuleCode(value="calldetailanalysis")
    @RequestMapping(method= RequestMethod.GET,value = "detail")
    public Object detail(ModelMap model){
        return "phonerecord/callanalysis/detail";
    }
    @ModuleCode(value="callfrequencyanalysis")
    @RequestMapping(method= RequestMethod.GET,value = "frequency")
    public Object frequency(ModelMap model){
        return "phonerecord/callanalysis/frequency";
    }


    @ModuleCode(value="calllawanalysis")
    @RequestMapping(method= RequestMethod.GET,value = "law")
    public Object law(ModelMap model){
        return "phonerecord/callanalysis/frequencyLaw";
    }
    
    @ModuleCode(value="commoncontactspeople")
    @RequestMapping(method= RequestMethod.GET,value = "commoncontactspeople")
    public Object commoncontactspeople(ModelMap model){
        return "phonerecord/callanalysis/commonContactsPeople";
    }

    @RequestMapping(method= RequestMethod.GET,value = "frequencyMap")
    public Object frequencyMap(ModelMap model){
        return "phonerecord/callanalysis/frequencyMap";
    }


    /**
     * 分页+多条件查询  通话详情分析
     * @param searchMap 查询条件封装
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @ResponseBody
    @RequestMapping(value="/detail/{page}/{size}",method= RequestMethod.POST)
    public Result detailSearch(CallanalysisVo searchMap , @PathVariable int page, @PathVariable int size){
        PageResult pageResult = callAnalysisService.detail(searchMap, page, size);
        return  new Result(true, StatusCode.OK,"查询成功",  pageResult);
    }
    @ResponseBody
    @RequestMapping(value="/detail_easyui",method= RequestMethod.POST)
    public PageResult detailSearch_easyui(PhoneSearchDto dto){
        PageResult pageResult = callAnalysisService.detail_easyui(dto);
        return  pageResult;
    }
    /**
     * @Author 刘中华
     * @Date 2019/6/1 14:03
     * @Param [dto]
     * @return 判断是否联网。
     * @Description
     **/
    @RequestMapping(value="/getMapOnLine")
    @ResponseBody
    public Object getMapOnLine(String line){
        if (line.equals("Extranet")){
            request.getSession().setAttribute("env", "Extranet");//有网
        }else{
            request.getSession().setAttribute("env", "Intranet");//没网
        }
        return "";
    }
    /**
     * 活动轨迹地图
     */
    @ResponseBody
    @RequestMapping(value="/detail_map",method= RequestMethod.POST)
    public Result detailSearchMap(CallanalysisVo searchMap ){
        PageResult pageResult = callAnalysisService.detail_map(searchMap);
        return  new Result(true, StatusCode.OK,"查询成功",  pageResult);
    }

    @RequestMapping("/export/detail")
    @ResponseBody
    public void phoneExportdetail(PhoneSearchDto dto) throws Exception {
        //设置导出Excel标题
        dto.setRows(Integer.MAX_VALUE);
        dto.setPage(1);
        String[] titles = new String[]{"主叫号码", "呼叫类型", "对方号码", "通话日期","通话时长", "主叫城市", "被叫城市", "基站号","小区号(LAC)"};
        List<Map<String, Object>> list = callAnalysisService.detail_easyui(dto).getRows();
        List exportData =getExportData_detail(list);
        phoneExport(titles,list,exportData);
    }
    @RequestMapping("/export/frequency")
    @ResponseBody
    public void phoneExportfrequency(HttpServletResponse response ,@RequestParam(required = false) Map searchMap) throws Exception {
        //设置导出Excel标题
        String[] titles = new String[]{"主叫号码",  "对方号码", "对方归属地", "通话次数", "总时长", "平均时长","开始日期", "结束日期"};
        List<Map<String, Object>> list = callAnalysisService.frequency(searchMap, 1, Integer.MAX_VALUE).getRows();
        List exportData =getExportData_frequency(list);
        phoneExport(titles,list,exportData);
    }
    @RequestMapping("/export/law")
    @ResponseBody
    public void phoneExportlaw(HttpServletResponse response ,@RequestParam(required = false) Map searchMap) throws Exception {
        //设置导出Excel标题
        String[] titles = new String[]{"日期","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","合计"};
        List<Map<String, Object>> list = (ArrayList<Map<String, Object>>)callAnalysisService.frequencyLaw(searchMap).get("data");
        List exportData =getExportData_law(list);
        phoneExport(titles,list,exportData);
    }
    @RequestMapping("/export/commonContactsPeople")
    @ResponseBody
    public void phoneExporCommonContactsPeople(HttpServletResponse response ,@RequestParam(required = false) Map searchMap) throws Exception {
    	String caseId = searchMap.get("CASEMANAGE_ID")==null?"":searchMap.get("CASEMANAGE_ID").toString();
        //设置导出Excel标题
        String service_number = (String) searchMap.get("SERVICE_NUMBER");
        String[] split = service_number.split(",");
        String[] titles = new String[split.length+2];
        titles[0]="共同联系人/嫌疑人";
        for (int i=0;i<split.length;i++){
            titles[i+1]=split[i];
        }
        PhoneSearchDto dto = new PhoneSearchDto();
        dto.setCaseId(caseId);
        dto.setBeginTime(searchMap.get("begin_time").toString());
        dto.setEndTime(searchMap.get("end_time").toString());
        dto.setFrequencyCount(searchMap.get("FREQUENCY_COUNT").toString());
        dto.setContactsCount(searchMap.get("CONTACTS_COUNT").toString());
        dto.setContactsPeopleCount(searchMap.get("CONTACTS_PEOPLE_COUNT").toString());
        dto.setPartyNumber(searchMap.get("PARTY_NUMBER").toString());
        dto.setServiceNumber(service_number);
        titles[split.length+1]="合计";
        List<Map<String, Object>> list = (ArrayList<Map<String, Object>>)callAnalysisService.commonContactsPeople_easyui(dto);
        List exportData =getExportData_commonContactsPeople(list);
        phoneExport(titles,list,exportData);
    }

    public void phoneExport(String[] titles,List<Map<String, Object>> list,List exportData) throws Exception {
        // 生成导出excel名称
        Date date = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String fileName = "话单详情分析统计" + dateFormat.format(date);
        // 把导出的内容写入到流里面
        byte[] content = ExcelUtil.writeExcel(titles, exportData);
        InputStream is = new ByteArrayInputStream(content);

        // 设置response参数，可以打开下载页面
        response.reset();
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));
        ServletOutputStream out = response.getOutputStream();
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = new BufferedInputStream(is);
            bos = new BufferedOutputStream(out);
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
        } catch (final IOException e) {
            throw e;
        } finally {
            if (bis != null) {
                bis.close();
            }
            if (bos != null) {
                bos.close();
            }
            //插入导出日志
            dataOperationLogService.save(null, super.getLoginUser(), new PhoneRecord(), new PhoneRecord(), SystemFlag.HD, ModuleFlag.CALLDETAILS, ActionType.EXPORT);
        }
    }
    
    /**
     * 通话详情分析d3init
     * @return
     */
    @RequestMapping(value="/callAnalysisD3Init",method= RequestMethod.GET)
    public String callAnalysisD3Init(){
    	return "/phonerecord/callanalysis/d3/phoneD3";
    }
    /**
     * 通话详情分析  d3
     * @param searchMap 查询条件封装
     * @return 结果
     */
    @ResponseBody
    @RequestMapping(value="/detail_d3",method= RequestMethod.POST)
    public Result detailSearchD3(@RequestBody(required = false) Map searchMap ){
        return new Result(true, StatusCode.OK,"查询成功",  callAnalysisD3Service.detail(searchMap));
    }
    /**
     * 共同联系人  d3
     * @param searchMap 查询条件封装
     * @return 结果
     */
    @ResponseBody
    @RequestMapping(value="/commonContactsPeople_d3",method= RequestMethod.POST)
    public Result commonContactsPeople_D3(@RequestBody(required = false) Map searchMap ){
        return  new Result(true, StatusCode.OK,"查询成功",  callAnalysisD3Service.commonContactsPeople_D3(searchMap));
    }

    /**
     * 分页+多条件查询  通话频率分析
     * @param searchMap 查询条件封装
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @ResponseBody
    @RequestMapping(value="/frequency/{page}/{size}",method= RequestMethod.POST)
    public Result frequency(@RequestBody(required = false) Map searchMap , @PathVariable int page, @PathVariable int size){
        String caseId = request.getSession().getAttribute("caseId") == null ? "" : request.getSession().getAttribute("caseId").toString();
        searchMap.put("CASEMANAGE_ID",caseId);
        PageResult pageResult = callAnalysisService.frequency(searchMap, page, size);
        return  new Result(true, StatusCode.OK,"查询成功",  pageResult);
    }
    @ResponseBody
    @RequestMapping(value="/frequency_easyui",method= RequestMethod.POST)
    public PageResult frequency_easyui(PhoneSearchDto dto){
        PageResult pageResult = callAnalysisService.frequency_easyui(dto);
        List<String> phoneCodeList = new ArrayList<String>();
		if(pageResult!=null && pageResult.getRows()!=null) {
			for(Map<String, Object> pr:(List<Map<String, Object>>) pageResult.getRows()) {
				if(pr.get("PARTY_LOCATION")!=null && isNumeric(pr.get("PARTY_LOCATION").toString())) {//判断对方号码归属地是否是电话区号
					String partyLocation = pr.get("PARTY_LOCATION").toString().trim();
					if(!phoneCodeList.contains(partyLocation)) {
						phoneCodeList.add(partyLocation);
					}
				}
			}
		}
		if(phoneCodeList.size()>0) {
			Map<String, String> phoneCodeMap = trackEventsService.getLocationByPhoneCode(phoneCodeList);
			for(Map<String, Object> pr:(List<Map<String, Object>>) pageResult.getRows()) {
				if(pr.get("PARTY_LOCATION")!=null && isNumeric(pr.get("PARTY_LOCATION").toString())) {//判断对方号码归属地是否是电话区号
					String partyLocation = pr.get("PARTY_LOCATION").toString().trim();
					if(phoneCodeMap.get(partyLocation)!=null) {
						pr.put("PARTY_LOCATION", phoneCodeMap.get(partyLocation).toString());
					}
				}
			}
		}
        return  pageResult;
    }
    
    private boolean isNumeric(String str){
	    Pattern pattern = Pattern.compile("[0-9]*");
	    return pattern.matcher(str).matches();   
	}
    
    /**
     * 通话频率地图分析
     * @param searchMap 查询条件封装
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @ResponseBody
    @RequestMapping(value="/frequency_map",method= RequestMethod.POST)
    public Result frequencyMap(String SERVICE_USER_INFORMATION,String PARTY_NUMBER ,String FREQUENCY_COUNT,String begin_time,String end_time,String SERVICE_NUMBER,String CASEMANAGE_ID){
        Map<String ,String> searchMap = new HashMap<>();
        searchMap.put("SERVICE_USER_INFORMATION",SERVICE_USER_INFORMATION);
        searchMap.put("PARTY_NUMBER",PARTY_NUMBER);
        searchMap.put("FREQUENCY_COUNT",FREQUENCY_COUNT);
        searchMap.put("begin_time",begin_time);
        searchMap.put("end_time",end_time);
        searchMap.put("SERVICE_NUMBER",SERVICE_NUMBER);
        searchMap.put("CASEMANAGE_ID",CASEMANAGE_ID);
        PageResult pageResult = callAnalysisService.frequencyMap(searchMap);
        return  new Result(true, StatusCode.OK,"查询成功",  pageResult);
    }

    /**
     * 通话频率  折线
     * @param searchMap 查询条件封装
     * @return 结果
     */
    @ResponseBody
    @RequestMapping(value="/brokenline",method= RequestMethod.POST)
    public Result frequencyBrokenLine(@RequestBody(required = false) Map<String,String> searchMap ){
        List frequency = callAnalysisService.frequencyBrokenLine(searchMap);
        return  new Result(true, StatusCode.OK,"查询成功",  frequency);
    }

    /**
     * 通话频率  折线详情
     * @param searchMap 查询条件封装
     * @return 结果
     */
    @ResponseBody
    @RequestMapping(value="/brokenline/{page}/{size}",method= RequestMethod.POST)
    public Result frequencyBrokenLineDetail(@RequestBody(required = false) Map<String,String> searchMap, @PathVariable int page, @PathVariable int size ){
        PageResult pageResult = callAnalysisService.frequencyDetail(searchMap, page, size);
        return  new Result(true, StatusCode.OK,"查询成功",  pageResult);
    }
    @ResponseBody
    @RequestMapping(value="/brokenline_easyui",method= RequestMethod.POST)
    public PageResult frequencyBrokenLineDetail_easyui(CallanalysisVo vo){
        PageResult pageResult = callAnalysisService.phoneDetail_easyui(vo);
        return  pageResult;
    }
    @RequestMapping(method= RequestMethod.POST,value = "/brokenlineExcel")
    @ResponseBody
    public void findDealFlowListExcel(CallanalysisVo vo, HttpServletResponse response )throws Exception{
        XSSFWorkbook workbook1 = new XSSFWorkbook();
        SXSSFWorkbook wb = new SXSSFWorkbook(workbook1, 100);
        //创建HSSFWorkbook对象(excel的文档对象)
        //建立新的sheet对象（excel的表单）
        Sheet sheet=wb.createSheet("通话详情");
        //在sheet里创建第二行
        Row row2=sheet.createRow(0);
        //创建单元格并设置单元格内容
        row2.createCell(0).setCellValue("机主号码");
        row2.createCell(1).setCellValue("呼叫类型");
        row2.createCell(2).setCellValue("对方号码");
        row2.createCell(3).setCellValue("通话日期");
        row2.createCell(4).setCellValue("通话时长");
        row2.createCell(5).setCellValue("基站号(CI)");
        row2.createCell(6).setCellValue("小区号(LAC)");
        row2.createCell(7).setCellValue("地址");
        //在sheet里创建第三行
        vo.setPage(1);vo.setRows(Integer.MAX_VALUE);
        PageResult pageResult = callAnalysisService.phoneDetail_easyui(vo);
        List<Map<String, Object>> content = pageResult.getRows();
        if (content!=null && content.size()>0){
            for (int i=0;i<content.size();i++){
                Map<String, Object> map = content.get(i);
                Row row3=sheet.createRow(i+1);
                row3.createCell(0).setCellValue((String) map.get("SERVICE_NUMBER"));
                row3.createCell(1).setCellValue(map.get("CALL_TYPE")==null?"":map.get("CALL_TYPE").toString().contains("0")?"主叫":"被叫");
                row3.createCell(2).setCellValue((String) map.get("PARTY_NUMBER"));
                row3.createCell(3).setCellValue(DateUtils.getDateString((Date) map.get("STARTING_TIME")));
                row3.createCell(4).setCellValue((String) map.get("TALK_TIME"));
                row3.createCell(5).setCellValue((String) map.get("CID"));
                row3.createCell(6).setCellValue((String) map.get("LAC"));
                row3.createCell(7).setCellValue((String) map.get("ADDRESS"));
            }
        }
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String fileName = "通话详情" + dateFormat.format(new Date());
        //输出Excel文件
        OutputStream output=response.getOutputStream();
        response.reset();
        response.setHeader("Content-disposition", "attachment; filename="+ ExcelUtils.toUtf8String(fileName+".xlsx"));
        response.setContentType("application/msexcel");
        wb.write(output);
        output.close();
        //添加导出日志
        dataOperationLogService.save(null, super.getLoginUser(), new PhoneRecord(), new PhoneRecord(), SystemFlag.HD, ModuleFlag.PHONERECORDEXPORT, ActionType.EXPORT);

    }


    /**
     *
     * @author 刘中华
     * @date 2018/12/20 10:16
     * @param [searchMap]
     * @return com.mairuide.entity.Result
     * @Description 通话规律分析
     */
    @ResponseBody
    @RequestMapping(value="/frequency_law",method= RequestMethod.POST)
    public Result frequencyLaw(@RequestBody(required = false) Map searchMap ){
        HashMap<String, Object> detail = callAnalysisService.frequencyLaw(searchMap);
        return  new Result(true, StatusCode.OK,"查询成功",  detail);
    }
    @ResponseBody
    @RequestMapping(value="/frequency_law_easyui",method= RequestMethod.POST)
    public List frequencyLaw_easyui(PhoneSearchDto dto ){
        List detail = callAnalysisService.frequencyLaw_easyui(dto);
        return  detail;
    }
    /**
     *
     * @author 刘中华
     * @date 2018/12/20 10:16
     * @param [searchMap]
     * @return com.mairuide.entity.Result
     * @Description 通话规律地图分析
     */
    @ResponseBody
    @RequestMapping(value="/frequency_law_map",method= RequestMethod.POST)
    public Result frequencyLawMap(@RequestBody(required = false) Map searchMap ){
        HashMap<String, Object> detail = callAnalysisService.frequencyLawMap(searchMap);
        return  new Result(true, StatusCode.OK,"查询成功",  detail);
    }
    /**
     *
     * @author 刘中华
     * @date 2018/12/20 10:16
     * @param [searchMap]
     * @return com.mairuide.entity.Result
     * @Description 通话共同联系人分析
     */
    @ResponseBody
    @RequestMapping(value="/commoncontactspeople2",method= RequestMethod.POST)
    public Result commonContactsPeople2(@RequestBody(required = false) Map searchMap ){
        HashMap<String, Object> detail = callAnalysisService.commonContactsPeople(searchMap);
        return  new Result(true, StatusCode.OK,"查询成功",  detail);
    }
    @ResponseBody
    @RequestMapping(value="/commoncontactspeople2_easyui",method= RequestMethod.POST)
    public List commonContactsPeople2_easyui(PhoneSearchDto dto ){
        List<Map<String, Object>> mapList = callAnalysisService.commonContactsPeople_easyui(dto);
        return  mapList;
    }

    public List getExportData_detail(List<Map<String, Object>> list){
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List lists = new ArrayList<Map<Integer, String>>();
        for (Map m : list) {
            Map<Integer, Object> map = new HashMap<Integer, Object>();
            //主叫号码
            map.put(0, m.get("SERVICE_NUMBER")==null?"":m.get("SERVICE_NUMBER"));
            //呼叫类型
            map.put(1, m.get("CALL_TYPE")==null?"":Integer.valueOf(m.get("CALL_TYPE").toString())==0?"主叫":"被叫");
            //对方号码
            map.put(2, m.get("PARTY_NUMBER")==null?"":String.valueOf(m.get("PARTY_NUMBER")));
            //通话日期
            map.put(3, m.get("STARTING_TIME")==null?"":sdf.format((Timestamp)m.get("STARTING_TIME")));
            //通话时长
            map.put(4, m.get("TALK_TIME")==null?"":String.valueOf(m.get("TALK_TIME")));
            //主叫城市
            map.put(5, m.get("SERVICE_LOCATION")==null?"":String.valueOf(m.get("SERVICE_LOCATION")));
            //被叫城市
            map.put(6, m.get("PARTY_LOCATION")==null?"":String.valueOf(m.get("PARTY_LOCATION")));
            //基站号
            map.put(7, m.get("CID")==null?"":String.valueOf(m.get("CID")));
            //LAC
            map.put(8, m.get("LAC")==null?"":String.valueOf(m.get("LAC")));
            //把map集合添加到lists集合
            lists.add(map);
        }
        return lists;
    }
    public List getExportData_frequency(List<Map<String, Object>> list){
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List lists = new ArrayList<Map<Integer, String>>();
        for (Map m : list) {
            Map<Integer, Object> map = new HashMap<Integer, Object>();
            //主叫号码
            map.put(0, m.get("SERVICE_NUMBER")==null?"":m.get("SERVICE_NUMBER"));
            //对方号码
            map.put(1, m.get("PARTY_NUMBER")==null?"":String.valueOf(m.get("PARTY_NUMBER")));
            //对方归属地
            map.put(2, m.get("PARTY_LOCATION")==null?"":String.valueOf(m.get("PARTY_LOCATION")));
            //通话次数
            map.put(3, m.get("COUNT")==null?"":String.valueOf(m.get("COUNT")));
            //总时长
            map.put(4, m.get("SUM_TALK_TIME")==null?"":String.valueOf(m.get("SUM_TALK_TIME")));
            //平均时长
            map.put(5, m.get("AVG_TALK_TIME")==null?"":String.valueOf(m.get("AVG_TALK_TIME")));
            //开始日期
            map.put(6, m.get("BEIGIN_TIME")==null?"":sdf.format((Timestamp)m.get("BEIGIN_TIME")));
            //结束日期
            map.put(7, m.get("END_TIME")==null?"":sdf.format((Timestamp)m.get("END_TIME")));
            //把map集合添加到lists集合
            lists.add(map);
        }
        return lists;
    }
    public List getExportData_law(List<Map<String, Object>> list){
        List lists = new ArrayList<Map<Integer, String>>();
        for (Map m : list) {
            int i=1;
            Map<Integer, Object> map = new HashMap<Integer, Object>();
            //时间段
            map.put(0, m.get("时间段")==null?"":String.valueOf(m.get("时间段")));
            //时间
            List<Map<String,Object>> timeVal = (List<Map<String,Object>>)m.get("timeVal");
            for(Map<String,Object> v:timeVal){
                String day = ((String) v.get("day")).split(" ")[1];
                map.put(i++,String.valueOf(v.get("count")).equals("0")?"":String.valueOf(v.get("count")));
            }
            //合计
            map.put(25, m.get("合计")==null?"":String.valueOf(m.get("合计")));
            //把map集合添加到lists集合
            lists.add(map);
        }
        return lists;
    }

    public List getExportData_commonContactsPeople(List<Map<String,Object>> list){
        List lists = new ArrayList<Map<Integer, String>>();
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Map<String,Object> m : list) {
            Map<Integer, Object> map = new HashMap<Integer, Object>();
            //Map<String,Map<String,Object>> m=(Map<String,Map<String,Object>>)m1;
            //对方手机号
            map.put(0, ((Map<String,Object>)m.get("ContactsPeople")).get("PARTY_NUMBER")==null?"":String.valueOf(((Map<String,Object>)m.get("ContactsPeople")).get("PARTY_NUMBER")));
            //时间
            List<Map<String,Object>> timeVal = (List<Map<String,Object>>)m.get("body");
            for (int i=0;i<timeVal.size();i++){
                Map<String, Object> stringObjectMap = timeVal.get(i);
                if (stringObjectMap==null){
                    map.put(i+1,"X");
                }else{
                    String count=String.valueOf(timeVal.get(i).get("COUNT"));
                    String SUM_TALK_TIME=String.valueOf(timeVal.get(i).get("SUM_TALK_TIME"));
                    Object min_starting_time = timeVal.get(i).get("MIN_STARTING_TIME");
                    Object max_starting_time = timeVal.get(i).get("MAX_STARTING_TIME");
                    String min_Time="";
                    String max_Time="";
                    if (min_starting_time!=null&&!"".equals(min_starting_time)){
                        min_Time=sdf.format((Timestamp)min_starting_time);
                    }
                    if (max_starting_time!=null&&!"".equals(max_starting_time)){
                        max_Time=sdf.format((Timestamp)max_starting_time);
                    }
                    map.put(i+1,"通话"+count+"次；累计"+SUM_TALK_TIME+"秒"+"；最早"+min_Time+"；最晚："+max_Time);
                }
            }
            //合计
            Map<String, Object> total = (Map<String, Object>) m.get("total");
            String count=String.valueOf(total.get("count_s"));
            String SUM_TALK_TIME=String.valueOf(total.get("SUM_TALK_TIME_s"));
            Object min_starting_time = total.get("minTime");
            Object max_starting_time = total.get("maxTime");
            String min_Time="";
            String max_Time="";
            if (min_starting_time!=null&&!"".equals(min_starting_time)){
                min_Time=sdf.format((Timestamp)min_starting_time);
            }
            if (max_starting_time!=null&&!"".equals(max_starting_time)){
                max_Time=sdf.format((Timestamp)max_starting_time);
            }
            map.put(timeVal.size()+1,"通话"+count+"次；累计"+SUM_TALK_TIME+"秒"+"；最早"+min_Time+"；最晚："+max_Time);
            lists.add(map);
        }
        return lists;
    }
}
